package dk.ucn.datamatiker.conceptgame;

import java.util.ArrayList;
import java.util.List;




import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.app.Activity;
import android.app.Activity.*;
import android.content.Intent;


public class Mail extends Activity {

	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Intent intent = getIntent();
		
		ArrayList<String> mails = intent.getStringArrayListExtra("Mail");
		ArrayList<String> words = intent.getStringArrayListExtra("Words");
		
		String[] mailtaks = mails.toArray(new String[mails.size()]);
		String[] wordtasks = words.toArray(new String[words.size()]);
		
		sendEmail(mailtaks, wordtasks);
		
		
	}
	
	
	protected void sendEmail(String[]mails, String[] words) {
		Log.i("Send email", "");
		
				
		String[] TO = mails;

		StringBuilder sb = new StringBuilder();
		for (String s : words)
		{
			sb.append(s);
			sb.append("\n");
		}
		
		Intent emailIntent = new Intent(Intent.ACTION_SEND);
		emailIntent.setData(Uri.parse("mailto:"));
		emailIntent.setType("text/plain");
		
		emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
		
	    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Game Words");
	    emailIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
	    
	    try {
	    	startActivity(Intent.createChooser(emailIntent, "Send Email..."));
	    	finish();
	    	Log.i("Finished sending email...", "");
			
		} 
	    catch (android.content.ActivityNotFoundException ex) {
			Toast.makeText(this, "There is no email client installed", Toast.LENGTH_SHORT).show();
		}
	    
	    
	
	    
	}
	
	
	
}
